<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8" />
		<meta http-equiv="X-UA-Compatible" content="IE=edge" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
		<title>Document</title>
	</head>
	<body>
		<div id="app">
			<ul>
				<li v-for="(item, index) in names" :key="index">{{item}}</li>
			</ul>

			<ul>
				<li v-for="(item, index) of names" :key="index">{{item}}</li>
			</ul>

			<button @click="changeArray">changeArray</button>
		</div>

		<script src="./js/vue.js"></script>
		<script>
			// 1. 创建app实例
			const app = Vue.createApp({
				data() {
					return {
						names: ['abc', 'cba', 'nba'],
					}
				},
				methods: {
					changeArray() {
						// this.names.push('张三')
						// this.names.pop('张三')

						// this.names.splice(2, 0, '张三')

						// 不能修改数组的方法时不能侦听（watch）
						this.names = this.names.map((item) => item + 1)
					},
				},
			})

			// 2. 挂载到#app上
			app.mount('#app')
		</script>
	</body>
</html>
